﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using HPT.Utilities;

namespace HPT
{
    public class PresenterRelatedNews
    {
        private IViewRelatedNews view;

        public PresenterRelatedNews(IViewRelatedNews view)
        {
            // TODO: Complete member initialization
            this.view = view;
        }
        //Get all news

        public void GetRelatedNews()
        {
            SPList listNews = OWeb.GetList(Constants.List.News);
            SPListItem newsResult = listNews.GetItemById(view.ID);
            NewsModal getNews = new NewsModal(newsResult);
            List<NewsModal> allNews = new List<NewsModal>();
            SPQuery query = new SPQuery();
            query.Query = String.Format("<Where><And><Or><IsNull><FieldRef Name='Publish' /></IsNull><Eq><FieldRef Name='Publish' /><Value Type='Boolean'>1</Value></Eq></Or><Lt><FieldRef Name='DisplayOrder' /><Value Type='Integer'>{0}</Value></Lt></And></Where><OrderBy><FieldRef Name='DisplayOrder' Ascending='False' /></OrderBy>", getNews.DisplayOrder);
            query.RowLimit = Convert.ToUInt32(view.RowLimit);
            SPListItemCollection itemNews = null;
            itemNews = listNews.GetItems(query);
            foreach (SPListItem item in itemNews)
                allNews.Add(new NewsModal(item));
            view.AllNews = allNews;
        }


    }
}
